﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Register2.aspx.cs" Inherits="Ashlen.Portal.Web.Views.Account.Register" %>

<asp:Content ID="registerContent" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">

        var ddlCountries;
        var ddlStates;
       // var myForm;

        function pageLoad() {
            ddlCountries = $get("country");
            ddlStates = $get("state");
            myForm = $get("registerForm");
            $addHandler(ddlCountries, "change", bindOptions);
           // $addHandler(myForm, "submit", bindForm);
            bindOptions();
        }

        function bindOptions() {
            ddlStates.options.length = 0;
            var countryId = ddlCountries.value;

            if (countryId) {
                var url = "../Account/GetStatesForCountry/" + countryId;
                getContent(url, bindOptionResults);
            }
        }

        function bindOptionResults(data) {
            var newOption;
            var found;
            found = false;
            for (var k = 0; k < data.length; k++) {
                newOption = new Option(data[k].Name, data[k].ID);
                if ($get("selectedState") != null) {
                    if (data[k].ID == $get("selectedState").value) {
                        newOption.selected = true;
                        found = true;
                    }
                }
                ddlStates.options.add(newOption);
            }
            if (found == false) {
                ddlStates.value = data[0].ID;
            }
        }

        /**** should be in library ***/
        function getContent(url, callback) {
            var request = new Sys.Net.WebRequest();
            request.set_url(url);
            request.set_httpVerb("GET");
            var del = Function.createCallback(getContentResults, callback);
            request.add_completed(del);
            request.invoke();
        }

        function getContentResults(executor, eventArgs, callback) {
            if (executor.get_responseAvailable()) {
                callback(eval("(" + executor.get_responseData() + ")"));
            }
            else {
                if (executor.get_timedOut())
                    alert("Timed Out");
                else if (executor.get_aborted())
                    alert("Aborted");
            }
        }

    </script>
    <h2>Account Creation</h2>
    <p>
        Use the form below to create a new account. 
    </p>
    <p>
        Passwords are required to be a minimum of <%=Html.Encode(ViewData["PasswordLength"])%> characters in length.<br />
        Items marked with an asterisk (*) are mandatory.        
    </p>
    <p>
        <span style="color: Red">Please enter a valid email. <br />You will be sent a confirmation
            link via email which you will need to click before you can log in.</span>
    </p>
    <%
        var errors = ViewData["errors"] as IList<string>;
        if (errors != null) {
            %>
                <ul class="error">
                <% foreach (string error in errors) { %>
                    <li><%= Html.Encode(error) %></li>
                <% } %>
                </ul>
            <%
        }
         %>
    <%= Html.Hidden("selectedState")%>"
    <form id="registerForm" method="post" action="<%= Html.AttributeEncode(Url.Action("Register")) %>">
        <div>
            <table>
                <tr>
                    <td>Username:</td>
                    <td><%= Html.TextBox("username") %>*</td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><%= Html.TextBox("email") %>*</td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><%= Html.Password("password") %>*</td>
                </tr>
                <tr>
                    <td>Confirm password:</td>
                    <td><%= Html.Password("confirmPassword") %>*</td>
                </tr>
                <tr>
                    <td>
                        Firstname:
                    </td>
                    <td>
                        <%= Html.TextBox("firstName") %>*
                    </td>
                </tr>
                <tr>
                    <td>
                        Lastname:
                    </td>
                    <td>
                        <%= Html.TextBox("lastName") %>*
                    </td>
                </tr>
                <tr>
                    <td>
                        Nickname:
                    </td>
                    <td>
                        <%= Html.TextBox("nickName") %>
                    </td>
                </tr>
                <tr>
                    <td>
                        Date of Birth:
                    </td>
                    <td>
                        <%= Html.TextBox("dateOfBirth") %>
                    </td>
                </tr>
                <tr>
                    <td>
                        Sex:
                    </td>
                    <td>
                        <%= Html.DropDownList(string.Empty, "sex", new SelectList(new List<string> { "M", "F"})) %>*
                    </td>
                </tr>
                <tr>
                    <td>
                        Mobile:
                    </td>
                    <td>
                        <%= Html.TextBox("mobile")%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Phone:
                    </td>
                    <td>
                        <%= Html.TextBox("phone")%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Country:
                    </td>
                    <td>
                        <%= Html.DropDownList("", "country")%>*
                    </td>
                </tr>
                <tr>
                    <td>
                        State:
                    </td>
                    <td>
                        <select id="state" name="state"></select>*
                    </td>
                </tr>
                <tr>
                    <td>
                        Postcode:
                    </td>
                    <td>
                        <%= Html.TextBox("postcode")%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Send Me Community Alerts:
                    </td>
                    <td>
                        <%= Html.CheckBox("acceptCommunityEmail", ViewState["acceptCommunityEmail"])%>
                    </td>
                </tr>
                <tr>
                    <td>
                        Send Me Promotions:
                    </td>
                    <td>
                        <%= Html.CheckBox("acceptAdvertisingEmail", ViewState["acceptAdvertisingEmail"])%>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <!--Register-->
                    <td><input type="submit" value="Register" /></td>
                </tr>
            </table>
        </div>
    </form>
</asp:Content>
